<?php
function getXML($url,$username){
	$cookie_jar = APP_PATH.'/cookies/'.$username.'.txt';
	
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, FALSE);
	curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
	curl_setopt($ch, CURLOPT_NOBODY, FALSE);
	curl_setopt($ch, CURLOPT_TIMEOUT, 120);
	$result = curl_exec($ch);
	curl_close($ch);

	return $result;
	
}

function postXML($url,$username){
	$cookie_file = APP_PATH.'/cookies/'.$username.'.txt';
	
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, FALSE);
	curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
	curl_setopt($ch, CURLOPT_NOBODY, FALSE);
	curl_setopt($ch, CURLOPT_TIMEOUT, 120);
	$result = curl_exec($ch);
	curl_close($ch);

	return $result;
	
}

function ztf_regexp($callno)
{
	$pattern = "/(T[A-Z])|[A-Z]/";
	$callno = strtoupper($callno);
	preg_match($pattern, $callno,$matches);
	return $matches[0];
}

function checkuser($username,$loushiid)
{
	$conditions = array('username' => $username);
	$users = spClass("users");
	$result = $users -> find($conditions);
	return $result;
}